package com.shanpin.shebao.web.controller;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.shanpin.core.http.MJsonView;
import com.shanpin.shebao.web.module.ad.WebAdService;
import com.shanpin.shebao.web.service.CacheService;

@Controller
@RequestMapping("/sync")
public class SyncController {

	static Logger log = LoggerFactory.getLogger(SyncController.class); 
	
	@Autowired
	private CacheService cacheService;
	@Autowired
	private WebAdService webAdService;
	
	/**
	 * 同步登录状态
	 * @param key
	 * @param uid
	 * @return
	 */
	@RequestMapping("/login")
	public Object syncLogin(String key, int uid) {
		if (StringUtils.isBlank(key)) {
			return MJsonView.fail();
		}
		if (uid < 1) {
			return MJsonView.fail();
		}
//		log.warn("sync-login  {}   {}", uid, key);
		cacheService.keyCache(key, uid);
		return MJsonView.ok();
	}
	
	
	/**
	 * 运营后台调用删除广告数据和图片。
	 * @param id
	 * @return
	 */
	@RequestMapping("/ad/del")
	public Object syncLogin(int id) {
		if (id < 1) {
			return MJsonView.fail();
		}
		boolean ret = webAdService.delAd(id);
		return ret ? MJsonView.ok() : MJsonView.fail();
	}
	

}
